<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <!-- jqgrid-->
    <link href="__STATIC__/layout/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/layout/css/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
</head>

<body style="color:#333;padding:3px;">

    <!-- 筛选 -->
     <div class="ibox-content">
          <form method="post" class="form-horizontal" enctype="multipart/form-data" id="f1">
          		<input type="hidden" name="type" id="type"/>
              <div class="form-group">
                  <label style="padding-top: 0" class="col-sm-1 control-label">主题<em style="color: red" >*</em>：</label>
                  <div class="col-sm-10">
                      <input type="text" name="title" class="form-control">
                  </div>
              </div>
               <div class="hr-line-dashed"></div>
               <div class="container-fluid">
               		
						 <input type="button" class="btn btn-w-m btn-info" id="dr" value="导入数据"/>
                  		<input type="file" name="wenjian" id="drfile" style="display: none;"/>
               		
                 		<span id="ts"></span>
                  <span>(至少导入一条预算明细) <a href="{:url('Xitongexcel/apyuasuan_daochu')}" target="_blank">AP费用预算导入格式下载</a></span>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                  <label style="padding-top: 0" class="col-sm-1 control-label">备注：</label>
                  <div class="col-sm-10">
                      <textarea style="height: 100px;" maxlength="500" name="remark" class="form-control"></textarea>
                  </div>
              </div>
            <div class="hr-line-dashed"></div>
             <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list">
                 
                </div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-sm btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach"    >
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>


            <div class="hr-line-dashed"></div>
              <div class="container-fluid text-center">
                <input class="btn btn-w-m btn-warning" type="button" id="caogao" value="保存为草稿">
                <input class="btn btn-w-m btn-primary" type="button" id="tijiao" value="保存并提交流程">
                <input class="btn btn-w-m btn-default" type="button" id="back" name="" value="返回">
              </div>
          </form>
          </div>
     
    <!-- 筛选 -->
    
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <!-- <script src="js/plugins/layer/layer.min.js"></script> -->

    
    <!-- 自定义js -->
    <script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>
     <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    
    <!-- ztree -->
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.excheck.js"></script>
    <!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script> -->
    <!--统计代码，可删除-->
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
    <script>


        $("#back").click(function(){
        	location.href="{:url('Apyusuan/manage')}";
        })
        //上传文件处理
        $("#dr").click(function(){
        	$("#drfile").trigger("click");
        })
        $("#drfile").change(function(){
        	$("#ts").html($(this).val());
        })
        //提交处理
        $("#caogao").click(function(){
        	//保存类型设为草稿
        	$("#type").val(1);
        	go_submits();
        })
        $("#tijiao").click(function(){
        	//保存类型设为草稿
        	$("#type").val(3);
        	go_submits();
        })
        //ajax提交
        function go_submits(){
        	 var formData = new FormData($('#f1')[0]);  
		     $.ajax({    
		          url: '{:url("Apyusuan/new_ap_add")}' ,  /*这是处理文件上传的servlet*/  
		          type: 'POST',    
		          data: formData,   
		          cache: false,    
		         contentType: false,  
          		processData: false,  
		          success: function (re) {    
		            if(re!=""){
		            	var jieguo=JSON.parse(re);
		            	if(jieguo["state"]==1){
		            		swal({
							title: "完成",
							text:  jieguo["msg"],
							type: "success"
							},function(){
								location.href="{:url('Apyusuan/manage')}";
							});
		            	}else{
		            	swal({
						title: "错误",
						text:  jieguo["msg"],
						type: "warning"
						});
		            	}
		            	
		            }else{
		            	 swal({
						title: "错误",
						text:  "系统繁忙请稍后再试",
						type: "warning"
						});
		            }
		          },    
		          error: function (re) {    
		              swal({
						title: "错误",
						text:  "系统繁忙请稍后再试",
						type: "warning"
						});
		          }    
		     });    
        }
    </script>
    
<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

         var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });

        $('#renyuan').on('click','.ren .close',function () {
            $(this).closest('.ren').remove()
        })
    });
   

</script>
</body>

</html>
